﻿using Bridge.Shared.Models;
using Emails;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace Bridge.System.HttpApi
{
    [Route("[controller]/[action]")]
    public class SysEmailController:AbpController
    {
        public readonly ISysEmailService _sysEmailService;

        public SysEmailController(ISysEmailService sysEmailService)
        {
            _sysEmailService = sysEmailService;
        }
        [HttpPost]
        public async Task<ResponseResult> SendEmailAsync()
        {
            //1. 准备收件人、主题和内容
            var toEmails = "416863813@qq.com";
            var subject = "测试邮件";
            var htmlMessage = "<h1>这是一封测试邮件</h1><p>使用MailKit发送</p>";

            // 拼接相对路径（根目录 + 相对路径）
            var filePath = Path.Combine("C:\\Users\\Administrator\\Desktop", "img", "10f171b65f02f16d5f6f223c4dfa36eb.png");
            //2. 准备附件（可以添加多个）
            var attachments = new List<Attachment>{
             new Attachment
             {
                 FilePath = filePath,
                 FileName = "附件图.png",
                 MimeType = "image/png"  // PNG图片的MIME类型
		     }
         };
            //3. 发送邮件
            //传递 cancellationToken 用于取消操作
            await _sysEmailService.SendEmailAsync(toEmails, subject, htmlMessage, attachments, HttpContext.RequestAborted);

            return ResponseResult.Success("邮件发送成功！");
        }

        [HttpPost]
        public async Task<ResponseResult<List<EmailMessageOutput>>> GetInboxMessagesAsync(int maxCount = 50)
        {
            return await _sysEmailService.GetInboxMessagesAsync();
        }
        [HttpPost]
        public  async Task<List<EmailMessageOutput>> GetInboxMessagesByPopAsync(int maxCount = 50)
        {
            return await _sysEmailService.GetInboxMessagesByPopAsync();
        }



    }
}
